function pageReady() {
    layui.use(['form', 'layer', 'layedit', 'laydate', 'upload'], function () {
        var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
            laypage = layui.laypage,
            upload = layui.upload,
            layedit = layui.layedit,
            laydate = layui.laydate,
            $ = layui.jquery;

        //$("#id").val(GetQueryString("id"));

        form.verify({

            typeCode: function (value) {

                var codeDatas = codes(value);
                if (codeDatas == false) {
                    return "该编码已存在"
                }
            },
            valCode: [
                /^[\w\d\.]*$/
                , '字典值编码由字母、数字、_、.组成'
            ]
        })

        form.on("submit(addNews)", function (data) {
            //弹出loading

            var typeName = $("#typeName").val();
            var typeCode = $("#typeCode").val();
            var description = $("#description").val();

            var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.1});
            // 实际使用时的提交信息
            $.post("/tu/sys/dictType/addEntity", {
                typeName: typeName,
                typeCode: typeCode,
                description: description,
            }, function (res) {

            })
            setTimeout(function () {
                top.layer.close(index);
                top.layer.msg("添加成功！");
                layer.closeAll("iframe");
                layuiFunciton.closeOpen();
                //刷新父页面
                //parent.location.reload();
            }, 500);
            return false;
        })

        //修改提交表单,字典类型表
        form.on("submit(updateSubmit)", function (data) {

            //弹出loading
            var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.1});
            // 实际使用时的提交信息
            $.post("/tu/sys/dictType/editEntity", {
                id: $("#id").val(),
                typeName: $("#typeName").val(),
                typeCode: $("#typeCode").val(),
                description: $("#description").val(),
            }, function (res) {

            })
            setTimeout(function () {
                top.layer.close(index);
                top.layer.msg("修改成功！");
                layer.closeAll("iframe");
                layuiFunciton.closeOpen();
                //刷新父页面
                //parent.location.reload();
            }, 500);
            return false;
        })


    })

    /*function GetQueryString(name)
     {
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
     }*/

    function codes(value) {
        var add;
        $.ajax({//异步请求返回给后台
            url: '/tu/sys/dictType/checkTypeCodeIsExist',
            type: 'POST',
            async: false,
            data: {
                typeCode: value
            },
            dataType: 'json',
            success: function (data) {
                add = data;
                //这里获取到数据执行显示
            }
        });
        return add;
    }
}
